#!/bin/bash
download_url=https://download.redis.io/releases
redis_name=redis
redis_version=6.0.9
redis_tar_gz=${redis_name}-${redis_version}.tar.gz
redis_downlowd_path=/tmp

function find_package(){
        find_it=`find ~/ -name ${redis_tar_gz}`
        echo ${find_it}
        if [ ! -f ${find_it} ];then
                printf "\033[41;37m %s \033[0m not not exists!Downloading...." ${find_it}
                wget -c ${download_url}/${redis_tar_gz} -O ${redis_downlowd_path}
        else
                printf "\033[35m %s \033[0m exists!starting uncompress!" ${find_it}
                tar xzvf ${find_it} -C /tmp
                cd $redis_downlowd_path/${redis_name}-${redis_version}
                make -j2
                sudo make install
                sed  -i 's/127.0.0.1/0.0.0.0/g' redis.conf
                sudo cp redis.conf /etc
                status=`ps aux|grep redis-server|awk -F " " '{print $2}'|xargs kill -9`
                nohup redis-server /etc/redis.conf &
        fi
}
find_package ${redis_version}
